import pandas as pd

data_index =pd.to_datetime(['20230110','20230115','20230118'])
data_ser=pd.Series([11,22,33],index=data_index)
data_index
data_ser
print(data_ser)
#%%
from datetime import datetime
import pandas as pd
data_demo=[[11,22,33],[44,55,66],[77,88,99],[100,101,102]]
date_list=[datetime(2023,1,23),datetime(2023,2,15),datetime(2023,3,15),datetime(2023,4,15)]
time_df=pd.DataFrame(data_demo,index=date_list)
time_df
print(time_df)
#%%
import numpy as np
import pandas as pd
date_list =['2020/05/30','2022/02/01','2020/6/1','2021/4/1','2022/6/1','2023/1/23']# 根据日期字符串生成DatetimeIndex类的对象
date_index= pd.to_datetime(date_list)# 创建Series类的对象，并指定索引是DatetimeIndex
date_ser = pd.Series(np.arange(6),index=date_index)
date_ser
print(date_ser)
#%%
date_ser['2020']
print(date_ser)
#%%
date_ser['2020/05/30']
print(date_ser)
#%%
date_ser.iloc[3]
print(date_ser)
#%%
sorted_ser=date_ser.sort_index()
sorted_ser
print(sorted_ser)
#%%
sorted_ser.truncate(before='2020/05/30')#截断这之前
print(sorted_ser)
#%%
sorted_ser.truncate(after='2020/05/30')
print(sorted_ser)
#%%
date_ran=pd.date_range('2023-01-01','2023-01-10')
date_ran
print(date_ran)
#%%
date_ran=pd.date_range(start='2023-01-01',periods=6)
date_ran
print(date_ran)
#%%
date_ran=pd.date_range(end='2023-01-10',periods=5)
date_ran
print(date_ran)
#%%
date_ran=pd.date_range(start='2023-01-10',periods=5,freq='5D')
date_ran
#%%
pd.date_range(start='2023/1/1 12:30:11', periods=5, tz='Asia/Hong_Kong', normalize=True)
print(date_ran)